<!DOCTYPE html><html lang="zh-CN"><head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>&#x8BBE;&#x7F6E;&#x8BED;&#x8A00;&#x73AF;&#x5883; (&#x5C40;&#x90E8;) | Moment.js &#x6587;&#x6863;</title>
  <link rel="stylesheet" href="static/css/style.css">
  <link rel="shortcut icon" href="http://momentjs.cn/static/img/moment-favicon.png">
  <link rel="stylesheet" href="static/css/atom-one-light.min.css">
</head>
<body class="is-moment">
  <div class="hero hero-oneline">
    <div class="hero-centered">
      <h1>&#x8BBE;&#x7F6E;&#x8BED;&#x8A00;&#x73AF;&#x5883; (&#x5C40;&#x90E8;)</h1>
    </div>
  </div>
  <div id="api-section-__FILENAME__">
    <div id="content" class="clearfix">
  
      <div id="column1" data-id="__ID__" class="interior">
        <header>
          <!-- <h1>设置语言环境 (局部)</h1> -->
          <div id="gtoc">
            <ul>
              <!-- <li>v</li> -->
              <li>
                <a href="index.html#/i18n/instance-locale/" name="toc">&#x8FD4;&#x56DE;&#x4E0A;&#x5C42;&#x6587;&#x6863;</a>
              </li>
              <li style="border: none;">
                <a href="javascript:window.open('https://github.com/momentjscn/moment-docs-cn/edit/master/moment/06-i18n/02-instance-locale.md');" rel="nofollow" target="_blank">&#x63D0;&#x4EA4;&#x4FEE;&#x6539;</a>
              </li>
              <!-- <li>
                <a href="/search__SEARCH_PARAM__" name="toc">搜索</a>
              </li> -->
            </ul>
          </div>
          <hr>
        </header>

        <div id="biz_item"></div>
  
        <div id="apicontent">
          <div id="content_left">
							<div class="docs-method-signature">
								<pre><code class="language-js">// &#x4ECE; 2.8.1 &#x7248;&#x672C;&#x5F00;&#x59CB;
moment().locale(String|Boolean);

// &#x5E9F;&#x5F03;&#x4E8E; 2.8.1 &#x7248;&#x672C;
moment().lang(String|Boolean);
</code></pre>

							</div>
<p>&#x5F53;&#x4F20;&#x9012;&#x53EF;&#x80FD;&#x9700;&#x8981;&#x683C;&#x5F0F;&#x5316;&#x4E3A;&#x4E0D;&#x540C;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x7684; moment &#x65F6;&#xFF0C;&#x5168;&#x5C40;&#x7684;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x914D;&#x7F6E;&#x53EF;&#x80FD;&#x4F1A;&#x51FA;&#x73B0;&#x95EE;&#x9898;&#x3002;</p>
<pre><code class="language-javascript">moment.locale(&apos;en&apos;); // &#x9ED8;&#x8BA4;&#x7684;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x4E3A;&#x82F1;&#x8BED;&#x3002;
var localLocale = moment();

localLocale.locale(&apos;fr&apos;); // &#x5C06;&#x6B64;&#x5B9E;&#x4F8B;&#x8BBE;&#x7F6E;&#x4E3A;&#x4F7F;&#x7528;&#x6CD5;&#x8BED;&#x3002;
localLocale.format(&apos;LLLL&apos;); // dimanche 15 juillet 2012 11:01
moment().format(&apos;LLLL&apos;); // Sunday, July 15 2012 11:01 AM

moment.locale(&apos;es&apos;); // &#x5C06;&#x5168;&#x5C40;&#x7684;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x66F4;&#x6539;&#x4E3A;&#x897F;&#x73ED;&#x7259;&#x8BED;&#x3002;
localLocale.format(&apos;LLLL&apos;); // dimanche 15 juillet 2012 11:01
moment().format(&apos;LLLL&apos;); // Domingo 15 Julio 2012 11:01

localLocale.locale(false); // &#x91CD;&#x7F6E;&#x5B9E;&#x4F8B;&#x7684;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x3002;
localLocale.format(&apos;LLLL&apos;); // Domingo 15 Julio 2012 11:01
moment().format(&apos;LLLL&apos;); // Domingo 15 Julio 2012 11:01
</code></pre>
<p>&#x5982;&#x679C;&#x4E0D;&#x5E26;&#x53C2;&#x6570;&#x8C03;&#x7528; <code>moment#locale</code>&#xFF0C;&#x5219;&#x4F1A;&#x83B7;&#x53D6;&#x8BE5; moment &#x4F7F;&#x7528;&#x7684;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x914D;&#x7F6E;&#x3002;</p>
<pre><code class="language-javascript">var fr = moment().locale(&apos;fr&apos;);
fr.localeData().months(moment([2012, 0])) // &quot;janvier&quot;
fr.locale(&apos;en&apos;);
fr.localeData().months(moment([2012, 0])) // &quot;January&quot;
</code></pre>
<p>&#x5982;&#x679C;&#x9700;&#x8981;&#x8BBF;&#x95EE; moment &#x7684;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x6570;&#x636E;&#xFF0C;&#x8FD9;&#x662F;&#x9996;&#x9009;&#x7684;&#x65B9;&#x5F0F;&#x3002;</p>
<p>&#x4ECE; <strong>2.3.0</strong> &#x5F00;&#x59CB;&#xFF0C;&#x8FD8;&#x53EF;&#x4EE5;&#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x6807;&#x8BC6;&#x7B26;&#x7684;&#x6570;&#x7EC4;&#x3002;
&#x5B83;&#x7684;&#x5DE5;&#x4F5C;&#x65B9;&#x5F0F;&#x4E0E;&#x5728;<a href="javascript:window.open('http://nodejs.cn/s/cQmLTv');" target="_blank" rel="nofollow">&#x5168;&#x5C40;&#x7684;&#x8BED;&#x8A00;&#x73AF;&#x5883;&#x914D;&#x7F6E;</a>&#x4E2D;&#x76F8;&#x540C;&#x3002;</p>
					</div>
          <div id="content_right">
							<div class="docs-method-signature">
								<pre><code class="language-js">// From version 2.8.1 onward
moment().locale(String|Boolean);

// Deprecated version 2.8.1
moment().lang(String|Boolean);
</code></pre>

							</div>
<p>A global locale configuration can be problematic when passing around moments that may need to be formatted into different locale.</p>
<pre><code class="language-javascript">moment.locale(&apos;en&apos;); // default the locale to English
var localLocale = moment();

localLocale.locale(&apos;fr&apos;); // set this instance to use French
localLocale.format(&apos;LLLL&apos;); // dimanche 15 juillet 2012 11:01
moment().format(&apos;LLLL&apos;); // Sunday, July 15 2012 11:01 AM

moment.locale(&apos;es&apos;); // change the global locale to Spanish
localLocale.format(&apos;LLLL&apos;); // dimanche 15 juillet 2012 11:01
moment().format(&apos;LLLL&apos;); // Domingo 15 Julio 2012 11:01

localLocale.locale(false); // reset the instance locale
localLocale.format(&apos;LLLL&apos;); // Domingo 15 Julio 2012 11:01
moment().format(&apos;LLLL&apos;); // Domingo 15 Julio 2012 11:01
</code></pre>
<p>If you call <code>moment#locale</code> with no parameters, you get back the locale configuration that would be used for that moment.</p>
<pre><code class="language-javascript">var fr = moment().locale(&apos;fr&apos;);
fr.localeData().months(moment([2012, 0])) // &quot;janvier&quot;
fr.locale(&apos;en&apos;);
fr.localeData().months(moment([2012, 0])) // &quot;January&quot;
</code></pre>
<p>If you need to access the locale data for a moment, this is the preferred way to do so.</p>
<p>As of <strong>2.3.0</strong>, you can also specify an array of locale identifiers. It works the same way it does in the <a href="#/i18n/changing-locale/" target="_blank" rel="nofollow">global locale configuration</a>.</p>
					</div>
          <div></div>
        </div>
      </div>
    </div>
  </div>
  
  <script src="static/js/highlight.min.js"></script>
  <script src="static/js/javascript.min.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
  <script>var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "//hm.baidu.com/hm.js?7a7f78c805fbacc7e075d34f153031aa"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })();</script>

  <style>
    .hero-centered {
      margin: 0;
          margin-left: 10px;
    }
#gtoc ul {
  list-style: none;
  margin-left: 0;
  line-height: 1.5rem;
  padding: 0;
}
#gtoc>ul>li {
  display: inline;
  border-right: 1px solid #000;
  margin-right: .4rem;
  padding-right: .4rem;
}
#gtoc>ul>li>a {
  color: #61b2a7;
}
#content_left {
  width: 49%;float: left;border-right: 1px solid #eee;    padding-right: 2%;
}
#content_right {
float: left;width: 48%;margin-left: 3%;
}
#column1 {
  padding: 0 2rem;
}
  </style>


</body></html>